#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QProcess>
#include<QPainter>
#include<QDebug>
#include<QTimer>
#include<QSoundEffect>
#include"mypushbutton.h"
#include<QMessageBox>
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //配置主场景
    //设置固定的大小
    setFixedSize(458,572);
    //设置图标
    setWindowIcon(QIcon(":/resource/background01.png"));
    //设置标题
    setWindowTitle("吉良吉影的幸福生活");

    //退出按钮
    connect(ui->actionQuit,&QAction::triggered,[=](){
        this->close();
    });
    //唤出游戏帮助界面
    connect(ui->actionHelp, &QAction::triggered, [this](){
    QMessageBox::information(this,"请帮帮吉良吉影","吉良吉影正在和女朋友在外约会，却碰到了超级恶人承太郎，请帮吉良吉影让所有图片都反转成吉良吉影的女友。");
    });

    //开始按钮音效
    QSoundEffect * startSound = new QSoundEffect(this);
    startSound -> setSource(QUrl(":/resource/TapButtonSound.wav"));
    QSoundEffect * backSound = new QSoundEffect(this);
    backSound -> setSource(QUrl(":/resource/BackButtonSound.wav"));

    //开始按钮
    MyPushButton* startBtn = new MyPushButton(":/resource/MenuSceneStartButton.png");
    startBtn->setParent(this);
    startBtn->move(this->width()*0.5-startBtn->width()*0.5,this->height()*0.7);

    //实例化选择关卡
    chooseScence = new ChooseLevelScene;
    connect(startBtn,&QPushButton::clicked,[=](){
        //播放音效
        startSound->play();
        //弹起特效
        startBtn->zoom1();
        startBtn->zoom2();

        //延时进入关卡选择场景并将自身隐藏
        QTimer::singleShot(500,this,[=](){
            chooseScence->setGeometry(this->geometry());
            this->hide();
            chooseScence->show();
        });
    });

    //实现返回
    connect(chooseScence,&ChooseLevelScene::chooseScenceBack,[=](){
        this->setGeometry(chooseScence->geometry());
        backSound->play();
        chooseScence->hide();
        this->show();
    });
}
void MainWindow::paintEvent(QPaintEvent*){
    QPainter painter(this);
    QPixmap pix;
    pix.load(":/resource/background01.png");

    painter.drawPixmap(0,0,this->width(),this->height(),pix);

    pix.load(":/resource/Title1.png");
    pix = pix.scaled(pix.width()*0.5,pix.height()*0.5);
    painter.drawPixmap(150,50,pix);
}
MainWindow::~MainWindow()
{
    delete ui;
}
